<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/vakata-jstree-7a976d1/dist/themes/default/style.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <!--图片热点标记插件-->
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <link href="assets/images/log.ico" rel="shortcut icon">
    <style type="text/css">
        .mapBall{
            width:20px;
            height:20px;
            background: red;
            border-radius: 50%;
            position: absolute;
        }
        .changeColor a:hover{
            color: black;
            cursor:pointer;
        }
    </style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <!--顶部导航栏开始-->
    <header id="top_header" class="main-header">
        <!-- Logo -->
        <a href="main_page.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>T</b>pson</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!--<img src="assets/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview ">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i>
                        <span>主页</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview active">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-yellow"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-yellow"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                <b>地图展示</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="map_show.html"><i class="fa fa-map-marker"></i> 地图展示</a> </li>
            </ol>
        </section>
        <section class="invoice">
            <div class="row">
                <div class="col-md-3">
                    <div class="box box-warning">
                        <div class="box-header">
                            <h4 class="box-title"><b>当前区域数据</b></h4>
                        </div>
                        <div class="box-body">
                            <div id="loction_tree"></div>
                        </div>
                    </div>
                </div>
                <div class="col-md-9">
                    <div class="box box-warning box-solid" style="margin-bottom: 0px">
                        <div class="box-header">
                            <h4 id="locations"></h4>
                        </div>
                        <div class="box-body">
                            <div class="row" id="area_display">
                                <div class="row">
                                    <div class="pad margin no-print">
                                        <div class="callout callout-info" style="margin: 0!important;">
                                            选择要标记的楼宇，描点后保存
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12" id="build_map_div">
                                    <div class="col-lg-4">
                                        <select id="build_select" class="form-control select2 build_select_class" style="width: 100%;"></select>
                                    </div>
                                    <div class="col-sm-3">
                                        <button class="btn btn-info fa fa-save" id="save_x_y">保存</button>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="text" id="map_pos_x">
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="text" id="map_pos_y">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <section class="invoice">
                        <div id="iPicture" data-interaction="hover">
                            <div class="ip_slide" id="map_div">
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
        <div class="clearfix"></div>
    </div><!-- /.content-wrapper -->
    <!--内容区结束-->
    <!--页脚开始-->
    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b>  3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
    <!--页脚结束-->
</div>

<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/fastclick/fastclick.min.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/vakata-jstree-7a976d1/dist/jstree.min.js"></script>
<script src="assets/cxSelect-master/js/jquery.cxselect.min.js"></script>
<!--图片热点标记插件-->
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script src="js/alert_check.js"></script>
<script>
    var server;
    var mapId = getParam('mapId') ;
    var mapAreaId = 0;
    var locationObjArr;
    var mapKeyValue = [];
    var hotSpotArr = [];
    var ignoreAlarmLocalId = new Array();
    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        getIgnoreAlarm();
        dataInit();
        treeinit();
        if(mapId){
            var name= getParam('name');
            sikp(mapId,name);
        }else {
            mapInit();
        }
        window.onload = checkAlert(server);
    });

    //初始化区域信息
    function dataInit() {
        $('#locations').empty();
        $('#map_div').empty();
        $.ajax({
            url: server + "/xk/xkGeoLocation/getTree",
            async:false,
            success:function (data_in) {
                var jsonObj = JSON.parse(data_in);
                var data = [];
                var ii = 0;
                for(var i  in jsonObj.data){
                    var level1 = jsonObj.data;
                    if(i==0){
                        var level1Obj = {
                            text:level1[i].name,
                            id:level1[i].id,
                            value:ii++,
                            level:1,
                            parentId:0,
                            icon:"glyphicon glyphicon-globe text-yellow",
                            state: {"opened" : true }
                        };

                    }else {
                        var level1Obj = {
                            text:level1[i].name,
                            id:level1[i].id,
                            value:ii++,
                            level:1,
                            parentId:0,
                            icon:"glyphicon glyphicon-globe text-yellow",
                            state: {"opened" : false }
                        };
                    }
                    if(level1[i].picture ==""){
                        level1Obj.text = level1[i].name + "(无地图)";
                    }
                    if(level1[i].children != null)
                    {
                        var level2 = level1[i].children;
                        var level2Arr = [];
                        var jj = 0;
                        for(var j in level2){
                            if(i==0 && j==0){
                                var level2Obj = {
                                    text: level2[j].name,
                                    id: level2[j].id,
                                    value:jj++,
                                    parentId:level1[i].id,
                                    posX:level2[j].posX,
                                    posY:level2[j].posY,
                                    level:2,
                                    icon: "glyphicon glyphicon-home text-yellow",
                                    state: {"opened" : true }
                                };
                            }else {
                                var level2Obj = {
                                    text: level2[j].name,
                                    id: level2[j].id,
                                    value:jj++,
                                    parentId:level1[i].id,
                                    posX:level2[j].posX,
                                    posY:level2[j].posY,
                                    level:2,
                                    icon: "glyphicon glyphicon-home text-yellow",
                                    state: {"opened" : false }
                                };
                            }
                            if(level2[j].picture ==""){
                                level2Obj.text = level2[j].name + "(无地图)";
                            }
                            if(level2[j].children != null)
                            {
                                var level3 = level2[j].children;
                                var level3Arr = [];
                                for(var k in level3){
                                    var level3Obj = {
                                        text: level3[k].name,
                                        id: level3[k].id,
                                        level:3,
                                        parentId:level2[j].id,
                                        icon: "glyphicon glyphicon-flag text-yellow"
                                    };
                                    if(level3[k].picture ==""){
                                        level3Obj.text = level3[k].name + "(无地图)";
                                    }
                                    level3Arr.push(level3Obj);
                                }
                                level2Obj .children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    data.push(level1Obj);
                }
                locationObjArr = data;
            }
        });
        $('#build_map_div').cxSelect({
            selects:['build_select_class'],
            jsonName:'text',
            jsonValue:'value',
            data:locationObjArr[mapAreaId].children
        });

    }
    function treeinit(){
        $('#loction_tree').data('jstree',false).empty();
        $('#loction_tree').jstree({
            'core' : {
                'data' : locationObjArr
            }
        });
    }
    function mapInit(){
        mapAreaId = locationObjArr[0].value;
        mapId = locationObjArr[0].id;
        var imgs = "";
        imgs = '<img id="show_map" style="width: 100%;height: 100%" class="ip_tooltipImg" style="width: 100%;height: 100%" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" />';
        $('#map_div ').append(imgs);
        var span = "";
        span =locationObjArr[0].text;
        span = "<span>" +"当前位置："+ span + "</span>";
        $('#locations').append(span);
        var area_display = document.getElementById("area_display");
        area_display.style.display = "";

    }
    $('#loction_tree').on('select_node.jstree', function (e, data) {
        mapId = data.node.id;
        $('#map_div').empty();
        $('#locations').empty();
        var imgs = "";
        imgs = '<img id="show_map" style="width: 100%;height: 100%" class="ip_tooltipImg" style="width: 100%;height: 100%" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" />';
        $('#map_div').append(imgs);

        var span = "";
        span =data.node.original.text;
        span = "<span>" +"当前位置："+ span + "</span>";
        $('#locations').append(span);

        level = data.node.original.level;
        if(level == 1){
            mapAreaId = data.node.original.value;
            console.log(mapAreaId);
            var area_display = document.getElementById("area_display");
            area_display.style.display = "";
            $('#build_map_div').cxSelect({
                selects:['build_select_class'],
                jsonName:'text',
                jsonValue:'value',
                data:locationObjArr[mapAreaId].children
            });
        }else if(level == 2){
            var area_display = document.getElementById("area_display");
            area_display.style.display = "none";

        }else if(level ==3){
            var area_display = document.getElementById("area_display");
            area_display.style.display = "none";
            setTimeout(" map_floor_init(mapId)",1000);
        }
    });
    //点击select变化时
    $('#build_select').on('change',function (e) {
        var mapbuildId = this.value;
        map_init(mapbuildId);
    });
    //建筑物热点刷新
    function map_init(mapbuildId){
        var buildFlag;
        var floorFlag;
        for(var build_j in ignoreAlarmLocalId){
            if(locationObjArr[mapAreaId].children[mapbuildId].id == ignoreAlarmLocalId[build_j].build){
                buildFlag = 1;
                break;
            }
        }
        if(buildFlag){
            var nameSelected = locationObjArr[mapAreaId].children[mapbuildId].text;
            $('#map_pos_x').val(locationObjArr[mapAreaId].children[mapbuildId].posX);
            $('#map_pos_y').val(locationObjArr[mapAreaId].children[mapbuildId].posY);
            $('#map_div').empty();
            var imgs = "";
            imgs = '<img id="show_map" style="width: 100%;height: 100%"  class="ip_tooltipImg" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" onclick="mapOnClick(event)" />';
            $('#map_div').append(imgs);
//        0.7\0.9是误差值
            var x = (parseFloat(locationObjArr[mapAreaId].children[mapbuildId].posX) * 100-0.7);
            x = x>0?x+'%':0;
            var y = (parseFloat(locationObjArr[mapAreaId].children[mapbuildId].posY) * 100-0.9);
            y = y>0?y+'%':0;
            var divs ="";
            divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';" data-tooltipbg="bgwhite" data-round="roundBgR" data-animationtype="btt-slide">' +
                    '<div class="row" style="height: auto;width: 100px;margin: auto">' +
                    '   <div class="box box-primary box-solid">' +
                    '       <div class="box-header"><h4>'+nameSelected+'</h4></div>' +
                    '       <div class="box-body">' +
                    '           <table class="table table-bordered table-striped">' +
                    '               <tbody id="'+nameSelected+'">' +
                    '               </tbody>' +
                    '           </table>' +
                    '       </div>' +
                    '       </div>' +
                    '   </div>' +
                    '</div>';
            $('#map_div').append(divs);
            $( "#iPicture" ).iPicture();
            var tr ="";
            for(var i in locationObjArr[mapAreaId].children[mapbuildId].children){
                floorFlag = 0;
                for(var floor_id in ignoreAlarmLocalId){
                    if(locationObjArr[mapAreaId].children[mapbuildId].children[i].id == ignoreAlarmLocalId[floor_id].floor){
                        floorFlag = 1;
                        break;
                    }
                }
                if(floorFlag){
                    tr += "<tr><td class='changeColor' style='border: solid;'><a onclick=sikp('"+locationObjArr[mapAreaId].children[mapbuildId].children[i].id+"','"+locationObjArr[mapAreaId].children[mapbuildId].children[i].text+"')><span style='color: red'>" + locationObjArr[mapAreaId].children[mapbuildId].children[i].text +"</span></a></td><tr>"
                }else {
                    tr += "<tr><td class='changeColor'><a onclick=sikp('"+locationObjArr[mapAreaId].children[mapbuildId].children[i].id+"','"+locationObjArr[mapAreaId].children[mapbuildId].children[i].text+"')>" + locationObjArr[mapAreaId].children[mapbuildId].children[i].text +"</a></td><tr>"
                }

            }
            $("#"+nameSelected).append(tr);
        }else{
            var nameSelected = locationObjArr[mapAreaId].children[mapbuildId].text;
            $('#map_pos_x').val(locationObjArr[mapAreaId].children[mapbuildId].posX);
            $('#map_pos_y').val(locationObjArr[mapAreaId].children[mapbuildId].posY);
            $('#map_div').empty();
            var imgs = "";
            imgs = '<img id="show_map" style="width: 100%;height: 100%"  class="ip_tooltipImg" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" onclick="mapOnClick(event)" />';
            $('#map_div').append(imgs);
//        0.7\0.9是误差值
            var x = (parseFloat(locationObjArr[mapAreaId].children[mapbuildId].posX) * 100-0.7);
            x = x>0?x+'%':0;
            var y = (parseFloat(locationObjArr[mapAreaId].children[mapbuildId].posY) * 100-0.9);
            y = y>0?y+'%':0;
            var divs ="";
            divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';" data-tooltipbg="bgwhite" data-round="roundBgG" data-animationtype="btt-slide">' +
                    '<div class="row" style="height: auto;width: 100px;margin: auto">' +
                    '   <div class="box box-primary box-solid">' +
                    '       <div class="box-header"><h4>'+nameSelected+'</h4></div>' +
                    '       <div class="box-body">' +
                    '           <table class="table table-bordered table-striped">' +
                    '               <tbody id="'+nameSelected+'">' +
                    '               </tbody>' +
                    '           </table>' +
                    '       </div>' +
                    '       </div>' +
                    '   </div>' +
                    '</div>';
            $('#map_div').append(divs);
            $( "#iPicture" ).iPicture();
            var tr ="";
            for(var i in locationObjArr[mapAreaId].children[mapbuildId].children){
                tr += "<tr><td class='changeColor'><a onclick=sikp('"+locationObjArr[mapAreaId].children[mapbuildId].children[i].id+"','"+locationObjArr[mapAreaId].children[mapbuildId].children[i].text+"')>" + locationObjArr[mapAreaId].children[mapbuildId].children[i].text +"</a></td><tr>"
            }
            $("#"+nameSelected).append(tr);
        }

    }
    function sikp(id,name){
        $('#map_div').empty();
        $('#locations').empty();
        var span = "";
        span =name;
        span = "<span>" +"当前位置："+ span + "</span>";
        $('#locations').append(span);

        var imgs = "";
        imgs = '<img id="show_map" style="width: 100%;height: 100%" class="ip_tooltipImg" style="width: 100%;height: 100%" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+id+'" />';
        $('#map_div').append(imgs);
        var area_display = document.getElementById("area_display");
        area_display.style.display = "none";
        setTimeout(" map_floor_init('"+id+"')",1000);
    }
    $( "#iPicture" ).iPicture();
//    保存按钮
    $('#save_x_y').click(function(){
        var value = $('#build_select').val();
        var id = locationObjArr[mapAreaId].children[value].id;
        var parentId = locationObjArr[mapAreaId].children[value].parentId;
        var level=locationObjArr[mapAreaId].children[value].level;
        var name = locationObjArr[mapAreaId].children[value].text;
        var posX = $('#map_pos_x').val().toString();
        var posY = $('#map_pos_y').val().toString();
        console.log("parentId:"+parentId);
        console.log(mapAreaId);
        console.log(value);
        var formDatas = new FormData();
        formDatas.append("id",id);
        formDatas.append("name",name);
        formDatas.append("parent_id",parentId);
        formDatas.append("level",level);
        formDatas.append("pos_x",posX);
        formDatas.append("pos_y",posY);
        $.ajax({
            type:"post",
            contentType : false,
            processData:false,
            url: server + "/xk/xkGeoLocation/update" ,
            data:formDatas,
            success:function (data) {
                if(JSON.parse(data).code == 0){
                    dataInit();
//                    treeinit();
                    map_init(value);
                }
                else{
                    layer.alert('操作失败：' + data,{
                        closeBtn: 0
                    });
                }
            }
        })
    })
//    获取未处理报警信号
    function getIgnoreAlarm(){
        $.ajax({
            url:server+"/xk/alarm/getAllIgnore" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in).data;
                for(var i in json){
                    var LocationId = {
                        area:json[i].geo_1_id,
                        build: json[i].geo_2_id,
                        floor:json[i].geo_3_id,
                        monitor:json[i].monitor_id,
                    }
                    ignoreAlarmLocalId.push(LocationId);
                }
            }
        });
    }
//    楼层坐标点初始化
    function map_floor_init(id){
        $('#map_div').find('div').each(function(){
            $(this).remove();
        });
        var w = $('#map_div').width();
        var h = $('#map_div').height();
        $.ajax({
            url:server +'/xk/xkMonitor/getFloor?id='+id,
            async:false,
            success:function(data){
                var jsonObj = JSON.parse(data).data;
                var monitorFlag;
                for(var i in jsonObj){
                    monitorFlag = 0;
                    if((!jsonObj[i].monitor_x)  && (!jsonObj[i].monitor_y)){
                        continue;
                    }
                    for(var monitor_i in ignoreAlarmLocalId){
                        if(jsonObj[i].id == ignoreAlarmLocalId[monitor_i].monitor){
                            monitorFlag=1;
                            break;
                        }
                    }
                    if(monitorFlag){
                        var x = parseFloat(jsonObj[i].monitor_x) * 100-0.7 ;
                        var y = parseFloat(jsonObj[i].monitor_y) * 100-0.9 ;
                        x = x>0?x+'%':0;
                        y = y>0?y+'%':0;
                        var divs = "";
                        divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';z-index: 100;"  data-tooltipbg="bgwhite" data-round="roundBgR" data-animationtype="ltr-slide" >' +
                                '<p style="width: 100%;height: 100%" class="changeColor">名称：<a onclick="editRecord('+jsonObj[i].id+')" style="width: 100%;height: 100%" >'+jsonObj[i].monitor_name+'</a></p>'+
                                '</div>';
                        $("#map_div").append(divs);
                    }else {
                        var x = parseFloat(jsonObj[i].monitor_x) * 100-0.7 ;
                        var y = parseFloat(jsonObj[i].monitor_y) * 100-0.9 ;
                        x = x>0?x+'%':0;
                        y = y>0?y+'%':0;
                        var divs = "";
                        divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';z-index: 100;"  data-tooltipbg="bgwhite" data-round="roundBgG" data-animationtype="ltr-slide" >' +
                                '<p style="width: 100%;height: 100%" class="changeColor">名称：<a onclick="editRecord('+jsonObj[i].id+')" style="width: 100%;height: 100%" >'+jsonObj[i].monitor_name+'</a></p>'+
                                '</div>';
                        $("#map_div").append(divs);
                    }

                }
                $( "#iPicture" ).iPicture();
            }
        })
    }
    //获取图片坐标值
    function mapOnClick(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#map_pos_x').val(x.toFixed(10));
        $('#map_pos_y').val(y.toFixed(10));
        var w = $('#map_div').width();
        var h = $('#map_div').height();

        $("#map_div .ip_img32").remove();
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#map_div .mapBall").remove();
        }
        posSetBall(w,h,x,y);
    }
    //画坐标点
    function posSetBall(w,h,x,y,name,id) {
        var curX = w * x;
        var curY = h * y;
        $('<span class="mapBall" title="'+name+'" onclick="editRecord('+id+')"></span>').css({
            width: 20,
            height: 20,
            left: curX + $('#map_div').position().left-28,
            top: curY + $('#map_div').position().top-28
        }).appendTo($('#map_div'));
    }
    function getParam(paramName) {
        paramValue = "";
        isFound = false;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
            arrSource = decodeURI(this.location.search).substring(1, this.location.search.length).split("&");
            i = 0;
            while (i < arrSource.length && !isFound) {
                if (arrSource[i].indexOf("=") > 0) {
                    if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                        paramValue = arrSource[i].split("=")[1];
                        isFound = true;
                    }
                }
                i++;
            }
        }
        return paramValue;
    }
    function editRecord(id) {
        var sensorLevel1;
        var sensorLevel2;
        var sensorLevel3;
        var name;
        var deviceName;
        var deviceId;
        var geoLevel1;
        var geoLevel2;
        var geoLevel3;
        var posX;
        var posY;
        var alarmNo;
        layer.open({
            type: 1,
            title:'监测点编辑',
            skin:'layui-layer-lan',
            area:['1300px', '900px'],
            content:'<div class="tab-pane" id="tab_0" style="width:98%">'
            +'  <div class="row">'
            +'      <div class="col-sm-12">'
            +'          <div class="box box-warning">'
            +'              <div class="box-header">'
            +'                  <h4 class="box-title"><b>2 修改监测点</b></h4>'
            +'              </div>'
            +'              <div class="box-body" id="change_monitor_box_body">'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.1 传感器类别</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div id="monitor_sensor_change_div">'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>一级</label>'
            +'                                  <select id="monitor_change_sensor1_select" class="form-control select2 monitor_change_sensor1_select_class" value></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>二级</label>'
            +'                                  <select id="monitor_change_sensor2_select" class="form-control select2 monitor_change_sensor2_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>三级</label>'
            +'                                  <select id="monitor_change_sensor3_select" class="form-control select2 monitor_change_sensor3_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3" id="monitor_change_router_div">'
            +'                          <div class="form-group">'
            +'                              <label>用户信息传输装置</label>'
            +'                              <select id="monitor_change_router_select" class="form-control select2 monitor_change_router_select_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.2 监测点地理位置</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="" id="monitor_change_location_div">'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>区域</label>'
            +'                              <select id="monitor_change_area_select2" class="form-control select2 monitor_change_area_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>建筑物</label>'
            +'                              <select id="monitor_change_build_select2" class="form-control select2 monitor_change_build_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>楼层</label>'
            +'                              <select id="monitor_change_floor_select2" class="form-control select2 monitor_change_floor_select2_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.3 设定新监测点名称与坐标点</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="col-sm-3">'
            +'                          <div class="form-group">'
            +'                              <label>监测点名称</label>'
            +'                              <input id="monitor_change_name_input" type="text" class="form-control" placeholder="请输入监测点名称">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3 ">'
            +'                          <div class="form-group">'
            +'                              <label>报警回路号</label>'
            +'                              <input id="monitor_change_alert_number_input" type="text" class="form-control">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2">'
            +'                          <div class="form-group">'
            +'                              <label>监测点X坐标</label>'
            +'                              <input id="monitor_change_pos_x_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2 ">'
            +'                          <div class="form-group">'
            +'                              <label>监测点Y坐标</label>'
            +'                              <input id="monitor_change_pos_y_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">地图点选</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div id="monitor_change_map_div" >'
            +'                      </div>'
            +'                  </div>'
            +'              </div>'
            +'          </div>'
            +'      </div>'
            +'  </div>'
            +'</div>'
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                var sensor_id = $('#monitor_change_sensor3_select').val();
                var geo_level_1_id = $('#monitor_change_area_select2').val();
                var geo_level_2_id = $('#monitor_change_build_select2').val();
                var geo_level_3_id = $('#monitor_change_floor_select2').val();
                var device_id = $('#monitor_change_router_select').val();
                var name = $('#monitor_change_name_input').val();
                var code = $('#monitor_change_alert_number_input').val();
                var pos_x = $('#monitor_change_pos_x_input').val();
                var pos_y = $('#monitor_change_pos_y_input').val();
                var formDatas = new FormData();
                formDatas.append("id",id);
                formDatas.append("sensor_id",sensor_id);
                formDatas.append("geo_level_1_id",geo_level_1_id);
                formDatas.append("geo_level_2_id",geo_level_2_id);
                formDatas.append("geo_level_3_id",geo_level_3_id);
                formDatas.append("device_id",device_id);
                formDatas.append("name",name);
                formDatas.append("code",code);
                formDatas.append("pos_x",pos_x);
                formDatas.append("pos_y",pos_y);
                $.ajax({
                    type:"post",
                    contentType : false,
                    processData:false,
                    url: server + "/xk/xkMonitor/update" ,
                    data:formDatas,
                    success:function () {
                        layer.alert('数据修改成功！',{
                            closeBtn: 0
                        });
                        map_floor_init(mapId);
                    }
                });
            },
            btn2:function (index,layero) {
            },
            success: function(){
                getMonitor(id);
                getEQ(deviceId);
                loadLoctionData(geoLevel1,geoLevel2,geoLevel3);
                getSensorType(sensorLevel1,sensorLevel2,sensorLevel3);
                $("#monitor_change_name_input").val(name);
                $("#monitor_change_alert_number_input").val(alarmNo);
                $("#monitor_change_pos_x_input").val(posX);
                $("#monitor_change_pos_y_input").val(posY);
                $('#monitor_change_map_div').empty();
                var imgs = "";
                imgs = '<img id="show_map2" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="'+server+'/xk/xkGeoLocation/mapDownload?id='+geoLevel3+'" onclick="mapOnClick2(event)" />';
                $('#monitor_change_map_div').append(imgs);
                setTimeout("initBall()",1000);
                $("#monitor_change_floor_select2").change(function(){
                    var mapId = $('#monitor_change_floor_select2').val();
                    $('#monitor_change_map_div').empty();
                    var imgs = "";
                    imgs = '<img id="show_map2" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" onclick="mapOnClick2(event)" />';
                    $('#monitor_change_map_div').append(imgs);
                    setTimeout("initBall()",1000);
                })
            }
        });
        //获取监测点信息
        function getMonitor(id){
            $.ajax({
                url:server + "/xk/xkMonitor/get?id=" + id,
                async:false,
                success:function(data_in){
                    var jsonobj = JSON.parse(data_in).data;
                    name = jsonobj.name;
                    deviceId = jsonobj.device_id;
                    geoLevel1 = jsonobj.geo_level_1_id;
                    geoLevel2 = jsonobj.geo_level_2_id;
                    geoLevel3 = jsonobj.geo_level_3_id;
                    sensorLevel1 = jsonobj.sensor_level_1_id;
                    sensorLevel2 = jsonobj.sensor_level_2_id;
                    sensorLevel3 = jsonobj.sensor_level_3_id;
                    posX = jsonobj.pos_x;
                    posY =jsonobj.pos_y;
                    alarmNo = jsonobj.description;
                }
            })
        }
        //获取用户信息传输装置信息
        function getEQ(deviceId) {
            $.ajax({
                url:server + "/xk/xkDevice/getAll",
                async:false,
                success:function (data) {
                    eqData = JSON.parse(data);
                    $('#monitor_change_router_div').cxSelect({
                        selects: ['monitor_change_router_select_class'],
                        jsonName: 'name',
                        jsonValue: 'id',
                        data:eqData.data
                    });
                    var cmb = document.getElementById("monitor_change_router_select");
                    option_items_select(cmb,deviceId);
                }
            });
        }
        //获取地理信息数据
        function loadLoctionData(geoLevel1,geoLevel2,geoLevel3) {
            $.ajax({
                url: server + "/xk/xkGeoLocation/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = JSON.parse(data_in);
                    mapData = [];     //地图信息
                    var data = [];     //地理信息
                    for(var i  in jsonObj.data){
                        var level1 = jsonObj.data;
                        var level1Obj = {
                            text:level1[i].name,
                            id:level1[i].id,
                        };
                        if(level1[i].children != null)
                        {
                            var level2 = level1[i].children;
                            var level2Arr = [];
                            for(var j in level2){
                                var level2Obj = {
                                    text: level2[j].name,
                                    id: level2[j].id,
                                };
                                if(level2[j].children != null)
                                {
                                    var level3 = level2[j].children;
                                    var level3Arr = [];
                                    for(var k in level3){
                                        var level3Obj = {
                                            text: level3[k].name,
                                            id: level3[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                        var floorObj = {
                                            id: level3[k].id,
                                            picture: level3[k].picture
                                        };
                                        mapData.push(floorObj);
                                    }
                                    level2Obj .children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        data.push(level1Obj);
                    }
                    loctionData = data;
                }
            });
            $('#monitor_change_location_div').cxSelect({
                selects: ['monitor_change_area_select2_class', 'monitor_change_build_select2_class', 'monitor_change_floor_select2_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:true,
                jsonSub: 'children',
                data:loctionData
            });
            var cmb1 = document.getElementById("monitor_change_area_select2");
            option_items_select(cmb1,geoLevel1);
            var i,j;
            for(i=0; i<loctionData.length;i++){
                if(loctionData[i].id == geoLevel1){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_build_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_build_select2");
                    option_items_select(cmb2,geoLevel2);
                    break;
                }
            }
            for(j = 0;j<loctionData[i].children.length;j++){
                if(loctionData[i].children[j].id == geoLevel2){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_floor_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_floor_select2");
                    option_items_select(cmb3,geoLevel3);
                    break;
                }
            }
        }
        //获取传感器列表
        function getSensorType(sensorLevel1,sensorLevel2,sensorLevel3) {
            $.ajax({
                url:server + "/xk/xkSensor/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = JSON.parse(data_in);
                    sensorData = [];
                    for(var i in jsonObj.data){
                        var level1Data = jsonObj.data;
                        var level1Obj = {
                            //id,parentid,菜单等级
                            id: level1Data[i].id,
                            text: level1Data[i].name,
                        };
                        if(level1Data[i].children != undefined){
                            var level2Data = level1Data[i].children;
                            var level2Arr = [];
                            for(var j in level2Data){
                                var level2Obj = {
                                    text: level2Data[j].name,
                                    id: level2Data[j].id,
                                };
                                if(level2Data[j].children != undefined)
                                {
                                    var level3Data = level2Data[j].children;
                                    var level3Arr = [];
                                    for(var k in level3Data){
                                        var level3Obj = {
                                            text: level3Data[k].name,
                                            id: level3Data[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                    }
                                    level2Obj.children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        sensorData.push(level1Obj);
                    }
                }
            });
            $('#monitor_sensor_change_div').cxSelect({
                selects: ['monitor_change_sensor1_select_class', 'monitor_change_sensor2_select_class','monitor_change_sensor3_select_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:true,
                jsonSub: 'children',
                data:sensorData
            });
            var cmb1 = document.getElementById("monitor_change_sensor1_select");
            option_items_select(cmb1,sensorLevel1);
            var i,j;
            for(i=0; i<sensorData.length;i++){
                if(sensorData[i].id == sensorLevel1){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor2_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_sensor2_select");
                    option_items_select(cmb2,sensorLevel2);
                    break;
                }
            }
            for(j = 0;j<sensorData[i].children.length;j++){
                if(sensorData[i].children[j].id == sensorLevel2){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor3_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_sensor3_select");
                    option_items_select(cmb3,sensorLevel3);
                    break;
                }
            }
        }
        //设置下拉框默认值
        function option_items_select(cmb,value){
            for(var i = 0;i<cmb.options.length;i++){
                if(cmb.options[i].value == value){
                    cmb.selectedIndex = i;
                    return;
                }
            }
        }
    }
    //坐标点初始化
    function initBall(){
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var x = $('#monitor_change_pos_x_input').val();
        var y = $('#monitor_change_pos_y_input').val();
        posSetBall2(w,h,x,y);
    }
    //获取图片坐标值
    function mapOnClick2(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#monitor_change_pos_x_input').val(x.toFixed(10));
        $('#monitor_change_pos_y_input').val(y.toFixed(10));
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#monitor_change_map_div .mapBall").remove();
        }
        posSetBall2(w,h,x,y)
    }
    //画坐标点
    function posSetBall2(w,h,x,y) {
        var curX = w * x;
        var curY = h * y;
        $('<span class="mapBall">').css({
            width: 20,
            height: 20,
            left: curX + $('#monitor_change_map_div').position().left-10,
            top: curY + $('#monitor_change_map_div').position().top-10
        }).appendTo($('#monitor_change_map_div'));
    }
</script>
</body>
</html>